package com.agileboot.domain.airport.reformDetail.db;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class SirReformDetailServiceImpl extends ServiceImpl<SirReformDetailMapper, SirReformDetailEntity> implements SirReformDetailService {
    @Override
    public boolean archiveProofByReformId(Long reformId, boolean archiveCorrective, boolean archivePrecaution) {
        if (!archiveCorrective && !archivePrecaution) {
            return false; // 无需更新
        }

        StringBuilder setSql = new StringBuilder();
        if (archiveCorrective) {
            setSql.append("old_corrective_action_proof = corrective_action_proof, ");
            setSql.append("corrective_action_proof = NULL, ");
        }
        if (archivePrecaution) {
            setSql.append("old_precaution_action_proof = precaution_action_proof, ");
            setSql.append("precaution_action_proof = NULL, ");
        }

        // 去掉结尾多余逗号
        String setClause = setSql.toString().replaceAll(",\\s*$", "");

        return this.lambdaUpdate()
                .eq(SirReformDetailEntity::getReformId, reformId)
                .setSql(setClause)
                .update();
    }

}
